<template>
	<div>
		<div class="tit">增加跟进记录：</div>
		<el-form ref="formData" :model="formData" :rules="rules"  label-width="80px" class="demo-ruleForm">
			<el-form-item label="沟通时间">
			  <el-date-picker format="yyyy-MM-dd dd:mm:ss" value-format="yyyy-MM-dd dd:mm:ss" v-model="formData.create_time" type="datetime" placeholder="选择日期时间"></el-date-picker>
			</el-form-item>
			<el-form-item label="沟通方式" prop="communication">
				<el-select v-model="formData.communication" placeholder="请选择沟通方式">
				  <el-option label="网上" value="1" />
				  <el-option label="柜台" value="2" />
				  <el-option label="电话沟通" value="3" />
				</el-select>
			</el-form-item>
			<el-form-item label="意向度">
				<el-rate style="margin-top: 10px;" v-model="formData.intention" />
			</el-form-item>
			<el-form-item label="沟通内容" prop="content">
				<el-input v-model="formData.content" type="textarea" :rows="2"></el-input>
			</el-form-item>
			<el-form-item label="">
				<el-checkbox v-model="checked" @change="chec">下次沟通时间</el-checkbox>
			</el-form-item>
			<el-form-item label="">
				<el-date-picker format="yyyy-MM-dd dd:mm:ss" value-format="yyyy-MM-dd dd:mm:ss" v-model="formData.next_time" type="datetime" placeholder="选择日期时间" :disabled="!checked"></el-date-picker>
			</el-form-item>
			<el-form-item label="">
				<el-button @click="rest">重置</el-button>
				<el-button type="info" @click="addFol('formData')">确定</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
import {addFollow} from '@/api/studentRecruit.js'
export default{
	data(){
		return{
			checked:false,
			formData:{
				create_time:'', //沟通时间
				student_id:0, //学生id
				communication:'', //沟通方式
				intention:0, //意向度
				content:'', //沟通内容
				next_time:'', //下次沟通时间
			},
			rules: {
			    communication: [
			        { required: true, message: '请选择沟通方式', trigger: 'blur,change' }
			    ],
			    content: [
			        { required: true, message: '请输入沟通内容', trigger: 'blur,change' }
			    ]
			}
		}
	},
	created() {
		this.formData.student_id = this.sturow.unid
	},
	methods:{
		//下次沟通时间是否选中
		chec(){
			console.log(this.checked);
			if(!this.checked){
				this.formData.next_time = ''
			}
		},
		//添加跟进
		addFol(formData){
			this.formData.student_id
			if(this.checked!=true){
				this.formData.next_time = ''
			}
			this.$refs[formData].validate((valid) => {
				if(valid){
					addFollow(this.formData).then(res => {
						if(res.code == 200){
							this.$message.success('跟进成功！')
							//跟进成功后清空表单
							Object.keys(this.formData).forEach(key => {
								if(key!='student_id'&&key!='intention'){
									this.formData[key] = ''
								}
							})
						}else{
							this.$message.error('跟进失败！')
						}
					})
				}
			})
		},
		rest(){
			this.formData.intention = 0
			this.checked = false
			Object.keys(this.formData).forEach(key => {
				if(key!='student_id'&&key!='intention'){
					this.formData[key] = ''
				}
			})
		}
	},
	props:{
		sturow:{
			type:Object,
			default:null,
		},
	}
}
</script>

<style>
	.tit{
		margin-left: 12px;
		font-weight: bold;
		font-size: 20px;
	}
</style>
